package src.Fourteen;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

public class WindowStateListener_Example extends JFrame {

    public static void main(String[] args) {
        WindowStateListener_Example example = new WindowStateListener_Example();
        example.setVisible(true);
    }

    public WindowStateListener_Example(){
        super();
       addWindowStateListener(new MyWindowStateListener());
       setTitle("捕获窗口状态事件");
       setBounds(100,100,500,375);
    }

    private class MyWindowStateListener implements WindowStateListener{

        @Override
        public void windowStateChanged(WindowEvent e) {
            int oldState = e.getOldState();
            int newState = e.getNewState();
            String from = "";
            String to = "";
            switch (oldState){
                case Frame.NORMAL:
                    from="正常化";
                    break;
                case Frame.MAXIMIZED_BOTH:
                    from="最大化";
                    break;
                default:
                    from="图标化";
            }
            switch (newState){
                case Frame.NORMAL:
                    to="正常化";
                    break;
                case Frame.MAXIMIZED_BOTH:
                    to="最大化";
                    break;
                default:
                    to="图标化";
            }
            System.out.println(from+"————>"+to);
        }

    }
}
